<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<html:html>
<head>
		
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<LINK href="styles/stylewang.css"  type=text/css rel=stylesheet>
		<LINK href="../styles/stylewang.css"  type=text/css rel=stylesheet>
		<LINK href="xtree.css"  type=text/css rel=stylesheet>
		<style type="text/css"></style>
	
		<title>CGProject</title>
		<html:base/>
</head>
<%String id = (String)request.getAttribute("ID");%>
<%String make_id = (String)request.getAttribute("makeId");%>
<body >
<table border="0" width="100%" cellspacing="0" id="table6">
	<tr>
		<td colspan="5" width="85%" id="onlybt">&nbsp;
		<b><bean:message key="shot"/>&nbsp;<font color="#990000"><bean:write name="Shot" property="shotName"/></font>&nbsp;<bean:message key="shot.information"/></b>
		<a href="../listMakeRela.do?Id=<%=id%>&Type=Shot"><font color="#0000FF">[<bean:message key="shot.changerelation"/>]</font></a>
		</td>
	</tr>
	<logic:equal name="NoMake" value="false"><tr>
		<td width="17%" id="btleftbian">
		<b>&nbsp; <bean:message key="makename"/><br></b></td>	
		<td width="17%"  id="btcenterbian">
		<b>&nbsp; <bean:message key="category"/><br></b></td>	
		<td  width="17%"  id="btcenterbian">
		<b>&nbsp; <bean:message key="expectedhours"/></b></td>	
		<td width="17%"  id="btcenterbian">
		<b>&nbsp; <bean:message key="make.status"/><br></b></td>		
		<td width="53%"  id="btrightbian">&nbsp; 
		<b><font face="Verdana"></font><br></b></td>		
	</tr></logic:equal>
	<logic:equal name="NoMake" value="true"><tr>
		<td width="17%" >&nbsp; 
		<font color="#990000"><bean:message key="make.nomake"/></font></td>		
		<td width="53%" >
		　</td>		
	</tr></logic:equal>
	<logic:iterate id="element" name="makes">
	<logic:equal name="element" property="makeId" value="<%=make_id%>">
	<html:form action="/modMake">
	<html:hidden property="id"/>
	<tr>
		<td width="17%" id="leftcenter">
		&nbsp;<html:text property="name" size="16"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;<bean:write name="element" property="category.categoryName"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;<html:text property="expectHours" size="16"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;
		<script language=javascript>
			var s=top.changeColor("<bean:write name="element" property="status.statusDisplay"/>");
			document.write(s);
		</script></td>		
		<td width="53%" id="rightcenter">
		&nbsp;<html:submit><bean:message key="submit"/></html:submit></td>	
	</tr>
	</html:form>
	</logic:equal>
	<logic:notEqual name="element" property="makeId" value="<%=make_id%>">
	<tr>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;<bean:write name="element" property="makeName"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;<bean:write name="element" property="category.categoryName"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;<bean:write name="element" property="exceptHours"/></td>
		<td width="17%" id="leftcenter">
		&nbsp;&nbsp;
		<script language=javascript>
	
			var s=top.changeColor("<bean:write name="element" property="status.statusDisplay"/>");
			document.write(s);
		</script></td>
		<td width="53%" id="rightcenter">
		&nbsp;<html:link page="/shotIndex.do" paramId="makeId" paramName="element" paramProperty="makeId">[<bean:message key="basicmodify"/>]</html:link>&nbsp;&nbsp;
		<a href="../del.do?FatherType=Shot&FatherId=<%=id%>&Type=Make&Id=<bean:write name="element" property="makeId"/>" onclick="return   confirm('ConfirmDelete')">[<bean:message key="delete"/>]</a></td>		
	</tr>
	</logic:notEqual >
	
	</logic:iterate><tr><td colspan="5">
         <table width="100%" border="0" cellspacing="0" cellpadding="0" id="tdtop">
            <tr>
              <td></td>
             </tr>
         </table>
        </td></tr>
</table>
<html:form action="/addMake">
<html:hidden property="id" value="<%=id%>"/>
<html:hidden property="type" value="Shot"/>
<table border="0" width="100%" cellspacing="0" id="tabletable" cellpadding="0">
		<tr>
			<td  width="8%" id="btleftbian">&nbsp; <font color="#990000"><bean:message key="make.add"/> </font>
			</td>
			<td width="32%" id="btcenterbian"><bean:message key="makename"/><br></td>
			<td width="40%" id="btcenterbian"><bean:message key="category"/><br></td>
			<td width="30%" id="btrightbian"><bean:message key="expectedhours"/><br></td>
		</tr>
		<tbody id="tbDetailUsed">
		<tr>
			<td width="8%" id="leftcenter"><input type="checkbox"  disabled name="record_select" ></td>
			<td width="32%" id="leftcenter">
			<html:text property="name" size="40" style="border:1px solid #FFFFFF; font-family: Tahoma; font-size: 11px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px"/></td>
			<td width="40%" id="leftcenter">
			<html:select property="category" style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px">
					<html:options  collection="Categories"
								   property="categoryId"
								   labelProperty="categoryName"/>
					<logic:empty name="Categories"><html:option value=""><bean:message key="nocategory"/></html:option></logic:empty>
				</html:select></td>
			<td width="30%" id="rightcenter">
			<html:text property="expectHours" size="10" style="border:1px solid #FFFFFF; "/></td>
		</tr>	
	
		</tbody>
		<tr>
			<td width="100%" id="rightbottom" colspan="4">
			<input type="button" value="Submit" name="B1" style="font-family: Tahoma; font-size: 11px" onClick="submitAddMake()">
			&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button"  value="IncreaseClause" onClick="addDetailProcess();" style="font-family: Tahoma; font-size: 11px">
			<input type="button" value="DeleteClause" style="font-family: Tahoma; font-size: 11px" onClick="delDetailProcess()"></td>
		</tr>
		</table>
		<table id="tbDetailPrepare" style="display:none" cellspacing="0" cellpadding="0">
			<tr>
				<td width="8%" id="leftcenter"><input type="checkbox" name="record_select" ></td>
				<td width="32%" id="leftcenter">
				<html:text property="name" size="40" style="border:1px solid #FFFFFF; font-family: Tahoma; font-size: 11px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px"/></td>
				<td width="40%" id="leftcenter">
				<html:select property="category" style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px">
					<html:options  collection="Categories"
								   property="categoryId"
								   labelProperty="categoryName"/>
				</html:select></td>
				<td width="30%" id="rightcenter">
				<html:text property="expectHours" size="10" style="border:1px solid #FFFFFF; font-family: Tahoma; font-size: 11px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px"/></td>
			</tr>
		</table>
</html:form>



</body>
</html:html>
<script language="javascript">
function submitAddMake()
{
	var counter=tbDetailUsed.rows;
	var wrong_counter1=0;
	var wrong_counter2=0;
	var wrong_counter3=0;
	var wrong_counter4=0;
	for(var l=0;l<counter.length;l++)
	{
		if(document.addMakeForm.category[l].value=="")
		{
			alert("The clause"+(l+1)+"need a category!");
			wrong_counter3++;
			break;
		}
	}
	for(var m=0;m<counter.length;m++)
	{
		for(var n=m;n<counter.length;n++)
		{
			if(document.addMakeForm.category[m].value==document.addMakeForm.category[n].value&&m!=n&&wrong_counter3==0)
			{
				alert(" "+(m+1)+"and "+(n+1)+" cannot use one category!");
				wrong_counter4++;
				break;
			}

		}
	}

	for(var i=0;i<counter.length;i++)
	{
		if(document.addMakeForm.name[i].value=="")
		{
			alert("Please input "+(i+1)+"'s name");
			wrong_counter1++;
			break;
		}
	}
	for(var j=0;j<counter.length;j++)
	{
		for(var k=j;k<counter.length;k++)
		{
			if(document.addMakeForm.name[j].value==document.addMakeForm.name[k].value&&j!=k&&wrong_counter1==0)
			{
				alert(" "+(j+1)+" and "+(k+1)+"cannot use the same name!");
				wrong_counter2++;
				break;
			}

		}
	}
	if(wrong_counter1!=0||wrong_counter2!=0||wrong_counter4!=0||wrong_counter3!=0)
	{
		return;
	}
	document.addMakeForm.submit();
}

function addDetailProcess(afterRowIndex)		//增加明细
{
	
	
	var alltbDetailUsed = document.all("tbDetailUsed").rows;
	
	var theFirstSelectedDetail;
	if (afterRowIndex==null)
	{
	  theFirstSelectedDetail=alltbDetailUsed.length-2;
	}
	else theFirstSelectedDetail=afterRowIndex;
	var newRow = document.all("tbDetailPrepare").rows[0].cloneNode(true);
	var desRow = alltbDetailUsed[theFirstSelectedDetail+1];
//		desRow.parentElement.insertBefore(newRow,desRow );
	desRow.parentElement.appendChild(newRow);
	
	return alltbDetailUsed.length;
}

function delDetailProcess()						//删除明细
{
	var tag="";
	var alltbDetailUsed = document.all("tbDetailUsed").rows;
	for(var ii=0;ii<alltbDetailUsed.length;ii++)
	{
		
		if (alltbDetailUsed[ii].all("record_select").checked==true)
		{
			tag="true";
			break;		
		}
		else
		{
			tag="false";
		}
	}
	if(tag=="false")
	{
		alert("Please select a clause");
	}
	else
	{
		for(var i=0;i<alltbDetailUsed.length;i++)
		{
			if (alltbDetailUsed[i].all("record_select").checked==true)
			{
				document.all("tbDetailUsed").deleteRow(i);
				i=i-1;
			}
		}
	}
}

</script>
